#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CNTL_Z '\032'
#define SLEN 81
int main(void)
{
	int pos;
	FILE* fp;
	char filename[SLEN];
	char words[SLEN];
	long last;
	printf("please enter the file name:\n");
	scanf("%s", filename);
	
	if((fp = fopen(filename, "rb")) == NULL)
	{
		fprintf(stderr, "can't open the file:\n");
		exit(EXIT_FAILURE);
	}
//	fseek(fp, 0L, SEEK_END);
//	last = ftell(fp);
	printf("please enter the postion:\n");	
	while((scanf("%d", &pos)) == 1 && (pos>=0)){
//		printf("%d\n", pos);
		fseek(fp, -pos, SEEK_END);
		fgets(words, SLEN, fp);
		if(words[strlen(words) -1] == '\n')
			words[strlen(words)-1] = '\0';
		printf("%s\n",words);
		printf("please enter the postion:\n");
	}
	puts("DONE!");
	return 0;
}
